home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: Moti Saadon <moti@netmanage.co.il>
- Newsgroups: comp.lang.c++
- Subject: [] overloding vc4.0
- Date: Wed, 24 Jan 96 16:41:53 PDT
- Organization: NetVision LTD.
- Message-ID: <NEWTNews.822530713.12255.moti@motisaad.netmanage.co.il>
- NNTP-Posting-Host: motisaan.netmanage.co.il
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
-
-
- Why can't I compile this code at vc++4.0?
- Thanks.
-
- //----------------------------begin code-----------------
-
- //temp.cpp
-
- #include <stdio.h>
- #include <iostream.h>
-
- class Tclass{
- public:
- int temp;
- };
-
-
- //Range exeption
- class Range {
- int low, hi, badIndex;
- public:
- Range (int l, int h, int b)
- { low = l; hi = h; badIndex = b; }
- void display()
- { printf("\nRange error {%d, %d} :%d",
- low, hi, badIndex); }
- };
-
-
- template <class Type>
- class Array {
- Type *array;
- int size; //size of the array
- public:
- Array (int sz)
- { array = new Type[size = sz];}
- ~Array () {delete [] array;}
- Type &operator [] (int i);
- };
-
- //now comes the definition of the subscript operator
- template <class Type>
- Type &Array::operator[] (int i)
- {
- if (i<0 || i>=size)
- throw Range(0, size-1, i);
- return array[i];
- }
-
- void func(Array<Tclass> &arr)
- {
- try {
- for (int i=0; i<5; i++)
- //do some work with arr[i]
- arr[i].temp = 0;
-
- }
- catch (Range &r) {
- // report error condition
- r.display();
- }
- }
-
-
- void main()
- {
- //define Array of size 50
- Array<Tclass> array(3);
- func(array);
- }
-
- //------------------------end of code ---------------------
-
-